<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\User;

class CheckPayPass
{
    /**
     * Handle an incoming request.
     * 验证是否设置支付密码中间件
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //如果有uid参数
        if ($request->has('uid')) {
            //用户 ID
            $uid = $request->get('uid');
            //查找用户
            $user = User::find($uid);
            //验证用户是否存在
            if (count($user) == 0) {
                //用户不存在
                return respF(1001);
            }
            //判断是否设置支付密码
            if (strlen($user->pay_pass) < 10) {
                //支付密码未设置
                return respF(2006);
            }
        }

        return $next($request);
    }
}
